package nio.bytebuffer;

import java.nio.ByteBuffer;

public class Allocate_AllocateDirect_Performance {

    public static void main(String[] args) {
        allocateDirect();
        allocate();
    }

    private static void allocateDirect() {
        long beginTime = System.currentTimeMillis();
        ByteBuffer buffer = ByteBuffer.allocateDirect(1900000000);
        for (int i = 0; i < 1900000000; i++) {
            buffer.put((byte)123);
        }
        long endTime = System.currentTimeMillis();
        System.out.println(endTime - beginTime); // 1746
    }

    private static void allocate() {
        long beginTime = System.currentTimeMillis();
        ByteBuffer buffer = ByteBuffer.allocate(1900000000);
        for (int i = 0; i < 1900000000; i++) {
            buffer.put((byte)123);
        }
        long endTime = System.currentTimeMillis();
        System.out.println(endTime - beginTime); // 1259
    }

}
